package com.hevery.web.filter;

import com.hevery.warpper.HttpServletRequestCopier;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @Author: Hevery
 * @Description:
 * @Date: Created on 2017/10/8
 * @Modified By:
 */
//@Component
public class RequestFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("requestfiler init ");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequestCopier requestCopier = new HttpServletRequestCopier((HttpServletRequest)request);
        byte[] copier = requestCopier.getCopy();
        System.out.println("ResuestBody :" + new String(copier,requestCopier.getCharacterEncoding()));
        filterChain.doFilter(requestCopier,response);
    }

    @Override
    public void destroy() {

        System.out.println("requestfilter destroy");
    }
}
